﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;


namespace XMK.Framework.Web
{
    /// <summary>
    /// oem认证页面基类
    /// </summary>
    public class BasePage : SecureWebPageBase
    {
        /// <summary>
        /// 设置oem认证的cookie信息
        /// </summary>
        public static void SetOemCookie()
        {
            SetCookie(OemSessionId);
        }
        /// <summary>
        /// 设置wind认证的cookie信息
        /// </summary>
        public static void SetWindCookie()
        {
            SetCookie(WindSessionId);
        }
        #region 私有方法
        /// <summary>
        /// oem认证的键
        /// </summary>
        private static string OemSessionId = "oem.sessionid";
        /// <summary>
        /// wind认证的键
        /// </summary>
        private static string WindSessionId = "wind.sessionid";
        /// <summary>
        /// 根据主键设置cookie变量
        /// </summary>
        /// <param name="sessionid">设置cookie的名称</param>
        private static void SetCookie(string sessionid)
        {
            string s = HttpContext.Current.Request.Params[sessionid];
            if (!string.IsNullOrEmpty(s))
            {
                HttpCookie o = HttpContext.Current.Request.Cookies[sessionid];
                if (o != null)
                {
                    o.Value = s;
                }
                else
                {
                    HttpCookie cookie = new HttpCookie(sessionid);
                    cookie.Expires = DateTime.MaxValue;
                    cookie.Value = s;
                    HttpContext.Current.Response.Cookies.Add(cookie);
                }
            }
        }
        #endregion
    }
}
